package com.hxj.admin.szjy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxj.admin.szjy.mapper.UsermanagerMapper;
import com.hxj.admin.szjy.pojo.po.Usermanager;
import com.hxj.admin.szjy.pojo.query.UserQuery;
import com.hxj.admin.szjy.service.UsermanagerService;
import com.hxj.common.core.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hxj
 * @since 2024-03-14
 */
@Service
public class UsermanagerServiceImpl extends ServiceImpl<UsermanagerMapper, Usermanager> implements UsermanagerService {

    @Autowired
    private UsermanagerMapper usermanagerMapper;


    @Override
    public Page<Usermanager> getAdminUserByDistNo(UserQuery userQuery) {
        Page<Usermanager> page = new Page<>(userQuery.getCurrent(), userQuery.getPageSize());
        LambdaQueryWrapper<Usermanager> qw = new LambdaQueryWrapper<Usermanager>().eq(Usermanager::getPmain, 7);
        if (StringUtil.isNotBlank(userQuery.getDistNo())) {
            qw = qw.like(Usermanager::getDistno, userQuery.getDistNo() + "%");
        }
        if (StringUtil.isNotBlank(userQuery.getUsername())) {
            qw = qw.like(Usermanager::getUsername, "%" + userQuery.getUsername() + "%");
        }
        return page(page, qw);
    }



    @Override
    public void saveUser(Usermanager entity) {
//        userService.listMaps(new QueryWrapper<>(new Usermanager(), "pmain").groupBy("pmain"));
        saveOrUpdate(entity);
    }

    public void test() {
        usermanagerMapper.selectCount(new QueryWrapper<>());
    }



}
